package radar;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.JFrame;

public class Radar implements WindowListener{
	private JFrame 			frame;
	private RadarPanel 		panel;
	private static Radar 	radar;
	
	public static Radar getInstance()
	{
		if(radar==null) 
			radar = new Radar();
		return radar;
	}
	
	private Radar()
	{
		System.out.println("NEW RADAR");
		Toolkit t = Toolkit.getDefaultToolkit();
		frame = new JFrame("RADAR");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setUndecorated(true);
		frame.setAlwaysOnTop(true);
		panel = new RadarPanel();
		frame.add(panel);
		frame.setPreferredSize(new Dimension(256, 256));
		frame.setMaximumSize(new Dimension(256, 256));
		frame.setMinimumSize(new Dimension(256, 256));
		frame.setLocation(5, t.getScreenSize().height-frame.getSize().height-64);
		frame.setResizable(false);
		frame.setVisible(true);
		panel.repaint();
	}
	
	public void close()
	{
		frame.dispose();
	}
	
	public RadarPanel getPanel()
	{
		return panel;
	}
	
	public void clear()
	{
		panel.repaint();
		panel.getGraphics().fillRect(0, 0, panel.getWidth(), panel.getHeight());
		panel.drawMap();
	}
	
	@Override
	public void windowActivated(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowClosed(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowClosing(WindowEvent e) {
		System.out.println("WINDOW CLOSED");
		frame.setVisible(false);
		e.getWindow().dispose();
		
	}

	@Override
	public void windowDeactivated(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowDeiconified(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowIconified(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowOpened(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}
}
